#include #include using namespace std; //file format - type of file - used for different purposes // a specific organization in which the fields/data are stored void main() { ofstream fout("stuff.out",ios::binary); int i = 1095585093; //happens to have a binary reprsentation of EMMA //write arguments // char* - address of where you want to get the data from // int - the number of bytes to write // & - the "address of" operator fout.write((char*)&i ,4); fout.close(); int j = 0; ifstream fin("stuff.out",ios::binary); fin.read((char*)&j,4); cout << j << endl; fin.close(); // why use binary files // more efficent // on average you will use less disk space // *Faster access to specific fields // Direct access to specific fields //Disadvantage to using binary files // You must have a specific file format } #include #include using namespace std; //file format - type of file - used for different purposes // a specific organization in which the fields/data are stored void main() { ofstream fout("stuff.out",ios::binary); for(int i = 0; i < 1000000;i++) { //int value = rand(); fout.write((char*)&i ,4); } //fout.close(); ifstream fin("stuff.out",ios::binary); int k; //for(int j = 0; j < 1000000;j++) //{ // fin.read((char*)&k ,4); // //cout << k << endl; //} //g - the get pointer fin.seekg(999899 * 4); fin.read((char*)&k ,4); cout << k << endl; fin.close(); }